package com.programbookstore.dao.impl;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.programbookstore.dao.BookDAO;
import com.programbookstore.model.Book;
@Repository
public class BookDAOImpl implements BookDAO{

	@Autowired
	private SessionFactory sessionFactory;
	
	@Override
	@SuppressWarnings("unchecked")
	public List<Book> ListBook() {
		return    sessionFactory.getCurrentSession().createQuery("From Book").list();
	
	}

	@Override
	public void updateBook(Book book) {
	sessionFactory.getCurrentSession().update(book);
		
	}

	@Override
	public void deleteBook(int id) {
		sessionFactory.getCurrentSession().delete(this.getBook(id));
		
	}

	@Override
	public void addBook(Book book) {
		sessionFactory.getCurrentSession().save(book);
		
	}

	@Override
	public Book getBook(int id) {
		sessionFactory.getCurrentSession().get(Book.class, id);
		return null;
	}

}
